package com.shyroke.daydayzhuanapi.mapper;

import cn.hutool.core.date.DateUtil;
import com.shyroke.daydayzhuanapi.dto.AdvertDto;
import com.shyroke.daydayzhuanapi.entity.AdvertEntity;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AdvertMapper {
    @Autowired
    private ModelMapper modelMapper;

    public AdvertDto entityToDto(AdvertEntity e) {
        AdvertDto dto = modelMapper.map(e, AdvertDto.class);
        if(dto.getCreateTime() != null){
            dto.setShowCreateTime(DateUtil.format(dto.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
        }
        if(dto.getEndTime() != null){
            dto.setShowEndTime(DateUtil.format(dto.getEndTime(),"yyyy-MM-dd HH:mm:ss"));
        }
        return dto;
    }

    public AdvertEntity dtoToEntity(AdvertDto advertdto) {
        return modelMapper.map(advertdto, AdvertEntity.class);
    }
}
